package com.demo.spring;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloSpring {
//    定义hello属性，该属性的值将通过Spring框架进行设置
    private String hello = null;

    /**
     * 输出方法，从Sping配置文件中获取属性并输出
     */
    public void print(){
        System.out.println("Spring say:," + this.getHello() + "!");
    }

    public String getHello() {
        return hello;
    }

    public void setHello(String hello) {
        this.hello = hello;
    }
    @Test
    public void testHelloSpring(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        HelloSpring helloSpring = (HelloSpring) context.getBean("helloSpring");
        helloSpring.print();
    }
}
